import React from 'react'
import {browserHistory,hashHistory,Route,IndexRoute,Router} from 'react-router'

import App from '../components/App'
import Login from '../components/Login'
import Center from '../components/Center'
import Myloan from '../components/Myloan'
import Activation from '../components/Activation'
import Account from '../components/Account'
import Details from '../components/Details'
import NotFound from '../components/NotFound'
import Contract from '../components/Contract'

function requireLogin(nextState, replaceState) {
    console.log(nextState);
    if(!sessionStorage.getItem('token')){
        replaceState({ nextPathname: nextState.location.pathname }, '/login');
    }else{
        if(sessionStorage.getItem('isActivation') === 0){
            replaceState({ nextPathname: nextState.location.pathname }, '/activation');
        }
    }
}

class RouterList extends React.Component{
    render(){
        return(
            <Router history={browserHistory}>
                <Route path='/' component={App}>
                    <IndexRoute component={Center} />
                </Route>
                <Route path='/login' component={Login} />
                <Route path='/myloan' component={Myloan}/>
                <Route path='/activation' component={Activation}/>
                <Route path='/account' component={Account}/>
                <Route path='/details/:id' component={Details}/>
                <Route path='/contract/:id' component={Contract}/>
                <Route path='*' component={NotFound}/>
            </Router>
        )
    }
}

export default RouterList